#include "common.h"

#ifdef USE_NVS

#ifndef __NONVOLATILESTORAGE_H__
#define __NONVOLATILESTORAGE_H__

typedef enum NvsOpt_t {
	NVS_STANDBY=0,
	NVS_READ,
	NVS_WRITE,
	NVS_ERASE
} NvsOpt;

#define NVS_MEM_SEGMENT_SIZE	8	//min:1(without data, only flag) max:128
#define NVS_MEM_SEGMENT_FLAG 0x61
typedef union NVS_MEM_SEGMENT_t {
	uchar raw[NVS_MEM_SEGMENT_SIZE];
	struct {
		uchar flag;	//must be the first element in the structure
		uchar forward_dir;
	};
} NVS_MEM_SEGMENT;

bool NVS_OPT_BYTE(uchar *dat, uint addr, NvsOpt opt);
bool NVS_INIT();
bool NVS_ISVALID();
bool NVS_LOAD();
bool NVS_STORE();
bool NVS_CLEAR();
NVS_MEM_SEGMENT* NVS_GET();
//debug function
uint NVS_ADDR();

#endif//__NONVOLATILESTORAGE_H__

#endif
